package d26

func largestSquareArea(bottomLeft [][]int, topRight [][]int) int64 {

	maxLength := 0
	for i := 0; i < len(bottomLeft); i++ {
		for j := i + 1; j < len(bottomLeft); j++ {
			bottomMinTop := IntMin(bottomLeft[i][0], bottomLeft[j][0]) - IntMax(topRight[i][0], topRight[j][0])
			leftMinRight := IntMin(bottomLeft[i][1], bottomLeft[j][1]) - IntMax(topRight[i][1], topRight[j][1])
			maxLength = IntMax(IntMin(bottomMinTop, leftMinRight), maxLength)
		}
	}
	return int64(maxLength) * int64(maxLength)
}

func IntMin(intA int, intB int) int {
	if intA < intB {
		return intA
	}
	return intB
}
func IntMax(intA int, intB int) int {
	if intA > intB {
		return intA
	}
	return intB
}
